import { get, post, put, del } from "@/utils/request";
import {
	LoginData,
	LoginRes,
	CaptchaImageRes,
	UserRes,
	AddUserParams,
	OperLogParams,
	OpenLogRes,
	FakeoginData,
} from "./types";
enum URL {
	// 登录
	login = "/login",
	// 获取用户信息
	getInfo = "/getInfo",
	// 获取验证码
	getCaptchaImage = "/captchaImage",
	// 退出登录
	logout = "/user/logout",
	// 修改密码
	resetPWD = "/system/user/resetPwd",
	// 后台获取用户列表
	getUserList = "/system/user/list?pageNum=1&pageSize=999",
	// 后台改变用户状态
	changeUserStatus = "/system/user/changeStatus",
	// 后台新增用户
	// 后台删除用户
	dealUser = "/system/user",
	// 后台获取操作日志列表
	getOperLogList = "/monitor/operlog/list",
}

const login = async (data: LoginData) => post<LoginRes>({ url: URL.login, data });
const fakelogin = async (data: FakeoginData) => post<LoginRes>({ url: URL.login, data });
const getCaptchaImage = async () => get<CaptchaImageRes>({ url: URL.getCaptchaImage });
const getInfo = async () => get<any>({ url: URL.getInfo });
const logout = async () => post<any>({ url: URL.logout });
const resetPWD = async (userId: string, password: string) =>
	put<any>({
		url: URL.resetPWD,
		data: {
			userId,
			password,
		},
	});
const getUserList = async () => get<UserRes>({ url: URL.getUserList });
const changeUserStatus = async (status: string, userId: number) =>
	put<any>({ url: URL.changeUserStatus, data: { userId, status } });
const addUser = async (data: AddUserParams) => post<any>({ url: URL.dealUser, data });
const delUser = async (userId: number) => del(<any>{ url: URL.dealUser + "/" + userId });
const getOperLogList = async (params: OperLogParams) =>
	get<OpenLogRes>({ url: URL.getOperLogList, params });
export {
	logout,
	login,
	getCaptchaImage,
	getInfo,
	resetPWD,
	getUserList,
	changeUserStatus,
	addUser,
	delUser,
	getOperLogList,
	fakelogin,
};
